<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('物料分类')"/>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li v-if="checkedSearch.indexOf('分类编码') != -1">
                            分类编码：<input type="text" name="itemTypeCode"/>
                        </li>
                        <li v-if="checkedSearch.indexOf('分类名称') != -1">
                            分类名称：<input type="text" name="itemTypeName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            <a class="btn btn-success btn-rounded btn-sm" @click="moreSearch()"><i class="fa fa-edit"></i>&nbsp;更多</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <el-dialog title="搜索条件" width="200px" :visible.sync="showMore">
            <el-row>
                <el-col :span="24">
                    <el-checkbox style="margin-left: 28px" :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
                    <el-checkbox-group v-model="checkedSearch" @change="handleCheckedSearchChange">
                        <el-checkbox style="display: block;margin-left: 28px" v-for="item in searches" :label="item" :key="item" v-cloak>{{item}}</el-checkbox>
                    </el-checkbox-group>
                </el-col>
            </el-row>
        </el-dialog>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add(100)" shiro:hasPermission="system:itemType:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="system:itemType:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-info" id="expandAllBtn">
                <i class="fa fa-exchange"></i> 展开/折叠
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-tree-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:itemType:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:itemType:remove')}]];

    var prefix = ctx + "system/itemType";

    const searchOptions = ['分类编码', '分类名称'];

    var app = new Vue({
        el: '.container-div',
        data: {
            showMore: false,
            checkAll: false,
            checkedSearch: ['分类名称'],
            searches: searchOptions,
            isIndeterminate: true
        },
        methods: {
            moreSearch(){
                this.showMore = true;
            },
            handleCheckAllChange(val){
                this.checkedSearch = val ? searchOptions : [];
                this.isIndeterminate = false;
            },
            handleCheckedSearchChange(value){
                let checkedCount = value.length;
                this.checkAll = checkedCount === this.searches.length;
                this.isIndeterminate = checkedCount > 0 && checkedCount < this.searches.length;
            }
        }
    })

    $(function () {
        var options = {
            code: "itemTypeId",
            parentCode: "parentId",
            treeShowField: "itemTypeName",
            uniqueId: "itemTypeId",
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            modalName: "物料分类",
            columns: [
                {
                    field: 'selectItem',
                    radio: true
                },
                {
                    field: 'itemTypeName',
                    title: '分类名称',
                    visible: true
                },
                {
                    field: 'orderNum',
                    title: '排序',
                    align: "left",
                    visible: true
                },
                {
                    field: 'itemTypeId',
                    title: 'ID',
                    align: "left",
                    visible: false
                },
                {
                    field: 'parentId',
                    title: '父级ID',
                    align: "left",
                    visible: false
                },
                {
                    field: 'itemTypeCode',
                    title: '分类编码',
                    align: "left",
                    visible: true
                },
                {
                    field: 'parentName',
                    title: '父级',
                    align: "left",
                    visible: true,
                    formatter: function(value, row, index){
                        if(value == null){
                            return "最高级"
                        }else{
                            return value
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function(value, row, index){
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.add(\'' + row.itemTypeId + '\')"><i class="fa fa-edit"></i>新增下级</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.itemTypeId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.itemTypeId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }
            ]
        };
        $.treeTable.init(options);
    });
</script>
</body>
</html>
